import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int sum=0;
        for(int i=1;i<=n;i++){
            if(isRight(i)){
                sum+=i;
            }
        }
        System.out.println(sum);
    }
    public static boolean isRight(int n){
        String str=String.valueOf(n);
        char[] ch=str.toCharArray();
        for(int i=0;i<ch.length;i++){
            if(ch[i]=='2'||ch[i]=='0'||ch[i]=='1'||ch[i]=='9'){
                return true;
            }
        }
        return false;
    }
}